package com.foo.bussinesslogic.news;

import org.example.www.news.GetAllNews;
import org.example.www.news.GetAllNewsResponse;
import org.example.www.news.GetNewsByCategory;
import org.example.www.news.GetNewsByCategoryResponse;
import org.example.www.news.GetNewsByKeyword;
import org.example.www.news.GetNewsByKeywordResponse;
import org.example.www.news.News;
import org.example.www.news.NewsArray;

import com.foo.news.GetAllNewsFault;
import com.foo.news.GetNewsByCategoryFault;
import com.foo.news.GetNewsByKeywordFault;
import com.foo.news.NewsSkeletonInterface;


import com.foo.dao.*;

public class newsBusiness implements NewsSkeletonInterface
{

	@Override
	public GetNewsByCategoryResponse getNewsByCategory(GetNewsByCategory getNewsByCategory) throws GetNewsByCategoryFault {
		
		GetNewsByCategoryResponse object = new GetNewsByCategoryResponse();
		
		String category = (String)getNewsByCategory.getCategory();
		
		NewsDAO dao = new NewsDAO();
		News[] newsResult = dao.getNewsByCategory(category);
		
		NewsArray array = new NewsArray();
		array.setNews(newsResult);
		object.setGetNewsByCategoryResponse(array);
		
		return object;
	}

	@Override
	public GetAllNewsResponse getAllNews(GetAllNews getAllNews) throws GetAllNewsFault {
			
		GetAllNewsResponse object = new GetAllNewsResponse();
	
		NewsDAO dao = new NewsDAO();
		News[] newsResult = dao.getAllNews();
		
		NewsArray array = new NewsArray();
		array.setNews(newsResult);
		object.setGetAllNewsResponse(array);
		
		return object;
	}

	@Override
	public GetNewsByKeywordResponse getNewsByKeyword(GetNewsByKeyword getNewsByKeyword) throws GetNewsByKeywordFault {
		GetNewsByKeywordResponse object = new GetNewsByKeywordResponse();
		
		String keyword = (String)getNewsByKeyword.getKeyword();
		
		NewsDAO dao = new NewsDAO();
		News[] newsResult = dao.getNewsByKeyword(keyword);
		
		NewsArray array = new NewsArray();
		array.setNews(newsResult);
		object.setGetNewsByKeywordResponse(array);
		
		return object;
	}

}
